//
//  DJMyWallAcountBindVC.m
//  daojiVideo
//
//  Created by tikeios_002 on 2024/6/11.
//

#import "DJMyWallAcountBindVC.h"

@interface DJMyWallAcountBindVC ()
@property (weak, nonatomic) IBOutlet UIView *nameView;
@property (weak, nonatomic) IBOutlet YBTextFild *nameInput;
@property (weak, nonatomic) IBOutlet UIView *accountView;
@property (weak, nonatomic) IBOutlet YBTextFild *accountInput;
@property (weak, nonatomic) IBOutlet UIView *phoneView;
@property (weak, nonatomic) IBOutlet YBTextFild *phoneInput;
@property (weak, nonatomic) IBOutlet UIButton *saveButton;
@property (strong, nonatomic)UIButton * rightButton;

@end

@implementation DJMyWallAcountBindVC

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"提现账户";
    self.saveButton.backgroundColor = MainColor;
//    UIBarButtonItem * delItem = [[UIBarButtonItem alloc] initWithTitle:@"解绑" style:UIBarButtonItemStylePlain target:self action:@selector(acountRemove)];
//
//    self.navigationItem.rightBarButtonItem = delItem;

    
    self.view.backgroundColor = viewback_black;
    self.nameView.backgroundColor = subviewback_black;
    self.nameView.layer.cornerRadius = 6;
    self.nameInput.layer.cornerRadius = 5;
    self.nameInput.layer.borderWidth = 1;
    self.nameInput.layer.borderColor = [UIColor whiteColor].CGColor;
    self.nameInput.backgroundColor = subviewback_black;
    self.nameInput.leftViewMode = UITextFieldViewModeAlways;
    self.nameInput.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 30)];
    self.accountView.layer.cornerRadius = 6;
    self.accountView.backgroundColor = subviewback_black;
    self.accountInput.layer.cornerRadius = 5;
    self.accountInput.layer.borderWidth = 1;
    self.accountInput.layer.borderColor = [UIColor whiteColor].CGColor;
    self.accountInput.leftViewMode = UITextFieldViewModeAlways;
    self.accountInput.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 30)];
    self.phoneView.backgroundColor = subviewback_black;
    self.phoneView.layer.cornerRadius = 6;
    self.phoneInput.layer.cornerRadius = 5;
    self.phoneInput.layer.borderWidth = 1;
    self.phoneInput.layer.borderColor = [UIColor whiteColor].CGColor;
    self.phoneInput.leftViewMode = UITextFieldViewModeAlways;
    self.phoneInput.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 30)];
    
    self.nameInput.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入提现账户真实姓名" attributes:@{NSForegroundColorAttributeName:COLOR_ALPH(255, 255, 255, 0.72),NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    self.accountInput.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入支付宝账户" attributes:@{NSForegroundColorAttributeName:COLOR_ALPH(255, 255, 255, 0.72),NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    self.phoneInput.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入手机号" attributes:@{NSForegroundColorAttributeName:COLOR_ALPH(255, 255, 255, 0.72),NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    
    [self.nameInput addTarget:self action:@selector(textFiledChange:) forControlEvents:UIControlEventEditingChanged];
    [self.phoneInput addTarget:self action:@selector(textFiledChange:) forControlEvents:UIControlEventEditingChanged];
    [self.accountInput addTarget:self action:@selector(textFiledChange:) forControlEvents:UIControlEventEditingChanged];
    
    self.phoneInput.formaterType = YBAFormatterTextFieldFormatterTypePhone;
    self.nameInput.maxLength = 10;
    self.accountInput.maxLength = 20;
    
    self.saveButton.layer.cornerRadius = 5;

    if(self.accountDic != nil){
        // 支付宝
        self.nameInput.text = self.accountDic[@"name"];
        self.accountInput.text = self.accountDic[@"accounts"];
        self.phoneInput.text = self.accountDic[@"mobile"];
        
        _rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 40)];
        [_rightButton setTitle:@"解绑" forState: UIControlStateNormal];
        _rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [_rightButton addTarget:self action:@selector(acountRemove) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_rightButton];
        
        self.saveButton.alpha = 0.35;
        self.saveButton.userInteractionEnabled = NO;
    }
}
- (void)textFiledChange:(UITextField *)tf{
    if(self.accountDic != nil && self.saveButton.userInteractionEnabled == NO){
        self.saveButton.alpha = 1;
        self.saveButton.userInteractionEnabled = YES;
    }
}
- (IBAction)addButtonAction:(id)sender {
    if(self.nameInput.text.length == 0){
        [YBMsgPop showPop:@"请填写你的姓名"];
        return;
    }
    
    if(self.accountInput.text.length == 0){
        [YBMsgPop showPop:@"请填写你的账户/手机号/邮箱"];
        return;
    }
    
    if(self.phoneInput.text.length != 13){
        [YBMsgPop showPop:@"请填写手机号正确的手机号码"];
        return;
    }
    
    [SVProgressHUDTool showWithStatus:nil];
    KMutableDic(sendDic)
    sendDic[@"type"] = @(1);
    sendDic[@"name"] = self.nameInput.text;
    sendDic[@"accounts"] = self.accountInput.text;
    sendDic[@"mobile"] = self.phoneInput.text;
    KWeakSelf
    if(self.accountDic == nil){
        [YBNetBase addAccountRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            if(code == 200){
                [YBMsgPop showPop:@"提现账户添加成功"];
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
    }else{
        sendDic[@"id"] = self.accountDic[@"id"];
        [YBNetBase editAccountRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            if(code == 200){
                [YBMsgPop showPop:@"提现账户修改成功"];
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
    }
}
-(void)acountRemove{
    [SVProgressHUDTool showWithStatus:nil];
    KMutableDic(sendDic);
    [sendDic setObject:self.accountDic[@"id"] forKey:@"id"];
    KWeakSelf
    [YBNetBase delAccountRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        [SVProgressHUDTool dismiss];
        if(code == 200){
            [YBMsgPop showPop:@"提现账户解绑成功"];
            weakSelf.nameInput.text = @"";
            weakSelf.accountInput.text = @"";
            weakSelf.phoneInput.text = @"";
            weakSelf.accountDic = nil;
            [weakSelf.rightButton removeFromSuperview];
            weakSelf.saveButton.alpha = 1;
            weakSelf.saveButton.userInteractionEnabled = YES;
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
-(void)showTextViewAddShowViewTo2{
    UIView * showTextViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 100, 360)];
    showTextViewViewTo1.backgroundColor = [UIColor whiteColor];
    showTextViewViewTo1.layer.cornerRadius = 8;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewViewTo1];
    
    UIImageView * showTextViewimgTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(K_AUTOLAYOUT_W(157.5), K_AUTOLAYOUT_W(260), K_AUTOLAYOUT_W(60), K_AUTOLAYOUT_W(60))];
    showTextViewimgTo2.layer.cornerRadius = K_AUTOLAYOUT_W(30);
    showTextViewimgTo2.clipsToBounds = YES;
    showTextViewimgTo2.contentMode = UIViewContentModeScaleAspectFill;
    showTextViewimgTo2.hidden = YES;
    [showTextViewViewTo1 addSubview:showTextViewimgTo2];
    
    UILabel *  showTextViewimgTo3 = [[UILabel alloc]initWithFrame:CGRectMake(K_AUTOLAYOUT_W(15), K_AUTOLAYOUT_W(35), K_AUTOLAYOUT_W(345), K_AUTOLAYOUT_W(25))];
    showTextViewimgTo3.font = FontBold(18);
    showTextViewimgTo3.textColor = ThreeColor;
    showTextViewimgTo3.textAlignment = NSTextAlignmentCenter;
    showTextViewimgTo3.hidden = YES;
    [showTextViewViewTo1 addSubview:showTextViewimgTo3];
}
- (NSString *)showTextViewGetNowTimerTo3{
    NSDateFormatter *showTextViewGetNowFa = [[NSDateFormatter alloc] init];
    [showTextViewGetNowFa setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [showTextViewGetNowFa stringFromDate:[NSDate date]];
}

@end
